package com.ssy.lingxi.product.common.enums;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 商品配送方式
 * @author jw.chen
 * @version 2.0.0
 * @date 2022/3/29
 */
public enum DeliveryTypeEnum {
    Logistics(1, "物流（默认）"),
    Self(2, "自提"),
    No_Delivery(3, "无需配送"),
    Logistics_Self(4, "物流+自提");

    private Integer code;
    private String name;

    DeliveryTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return LanguageHolder.getName(this.getDeclaringClass(), this.getCode());
    }

    public static String getNameByCode(Integer code) {
        DeliveryTypeEnum typeEnum = Arrays.stream(DeliveryTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return typeEnum == null ? "" : typeEnum.getName();
    }
}
